<?php
/** 
* Faz n formatos de publicidades do adsense
* 
* @author Renato Ipiranga <ripiramga@gmail.com> 
* @version 0.1
* @access public
* Mais informações ({@link https://codex.wordpress.org/Widgets_API}) 
* e ({@link http://xref.wordpress.org/branches/3.6/WordPress/Widgets/WP_Widget.html})
*/


class Avpt_Adesense extends WP_Widget {
	function __construct() {
		parent::__construct( 'Avpt_Adesense', 'Avpt Adsense', array( 'description' => 'Adiciona um adsense' ) );
	}
	
	function widget($args, $instance) {
		include_once 'functions.php';
		extract($args, EXTR_SKIP);
		$title = empty ($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		$formato = empty ($instance['formato']) ? '' : apply_filters('widget_title', $instance['formato']);
		$up = empty ($instance['up']) ? '0' : apply_filters('up', $instance['up']);
		$down = empty ($instance['down']) ? '0' : apply_filters('down', $instance['down']);		
				
		if ( (strcmp($formato, 'formato1') == 0) ) { ?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:250px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>
				<?php delivery_adsense_code ( '250x250' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( (strcmp($formato, 'formato2') == 0) ) { ?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:320px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>
				<?php delivery_adsense_code ( '320x50' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( (strcmp($formato, 'formato3') == 0) ) { ?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:300px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>
				<?php delivery_adsense_code ( '300x250' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( strcmp($formato, 'formato4') == 0 ) {?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:300px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>
				<?php delivery_adsense_code ( '300x600' )?>>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( strcmp($formato, 'formato5') == 0 ) {?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:468px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>
				<?php delivery_adsense_code ( '468x15' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( strcmp($formato, 'formato6') == 0 ) {?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:468px;margin:auto" ><div>
				<span class="pub-retranca">PUBLICIDADE</span>
				<?php delivery_adsense_code ( '468x60' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( strcmp($formato, 'formato7') == 0 ) {?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div>			
				<?php echo add_google_pub_bloco_2x468x60 (); ?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>
		<?php
		}
		if ( strcmp($formato, 'formato8') == 0 ) {?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:728px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>			
				<?php delivery_adsense_code ( '728x90' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>			
		<?php
		}
		if ( strcmp($formato, 'formato9') == 0 ) {?>
			<div class="<?php echo 'vertical_space_'.$up?>"></div>
			<div style="width:970px;margin:auto" >
				<span class="pub-retranca">PUBLICIDADE</span>			
				<?php delivery_adsense_code ( '970x90' )?>
			</div>
			<div class="<?php echo 'vertical_space_'.$down ?>"></div>			
		<?php
		}
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['formato'] = strip_tags($new_instance['formato']);
		$instance['up'] = strip_tags($new_instance['up']);
		$instance['down'] = strip_tags($new_instance['down']);
		return $instance;
	}

	function form($instance) {
		$instance = wp_parse_args((array) $instance, array('title' => '', 'formato' => '', 'up' => '', 'down' => '' ));
		$title = strip_tags($instance['title']);
		$formato = strip_tags($instance['formato']);
		$up = strip_tags($instance['up']);
		$down = strip_tags($instance['down']);
		?>
		<p>
		  <label for="<?php echo $this->get_field_id('title');?>"><?php _e('Título: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($title); ?>">
		  <span class="nota-input-box">Opcional</span>
		</p>
		<p>		  
		  <label for="<?php echo $this->get_field_id('formato');?>"><?php _e('Escolha o formato: ') ?></label><br />
		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato1" <?php if($formato=='formato1'){echo 'checked';} ?>> 250x250<br />
		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato2" <?php if($formato=='formato2'){echo 'checked';} ?>> 320x50 - Telemóvel<br />		  
		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato3" <?php if($formato=='formato3'){echo 'checked';} ?>> 300x250<br />
  		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato4" <?php if($formato=='formato4'){echo 'checked';} ?>> 300x600<br />
  		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato5" <?php if($formato=='formato5'){echo 'checked';} ?>> 468x15<br />
  		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato6" <?php if($formato=='formato6'){echo 'checked';} ?>> 468x60<br />
  		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato7" <?php if($formato=='formato7'){echo 'checked';} ?>> 2x468x60<br />
  		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato8" <?php if($formato=='formato8'){echo 'checked';} ?>> 728x90<br />
  		  <input type="radio" class="widefat" id="<?php echo $this->get_field_id('formato'); ?>" name="<?php echo $this->get_field_name('formato'); ?>" value="formato9" <?php if($formato=='formato9'){echo 'checked';} ?>> 970x90<br />
		</p>	 
		<p>  
		  <label for="<?php echo $this->get_field_id('up');?>"><?php _e('Espaço acima em px: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('up'); ?>" name="<?php echo $this->get_field_name('up'); ?>" value="<?php echo esc_attr($up); ?>">		
		  <label for="<?php echo $this->get_field_id('down');?>"><?php _e('Espaço abaixo em px: ') ?></label>
		  <input class="widefat" id="<?php echo $this->get_field_id('down'); ?>" name="<?php echo $this->get_field_name('down'); ?>" value="<?php echo esc_attr($down); ?>">
		</p>
		<?php		
	}

}
